" Description: Plugins configurations, managed by vim-plug, coc.nvim

" Install: curl -fLo ~/.config/vim/vimfiles/autoload/plug.vim --create-dirs \
"       https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim

" set nocompatible              " be iMproved, required
call plug#begin($VIM.'/vimfiles/plugged')

" { Coc.nvim        语言插件管理平台
    Plug 'neoclide/coc.nvim', {'branch': 'release'}
    let g:airline#extensions#coc#enabled = 0
    " autocmd CursorHold * silent call CocActionAsync('highlight')
    " 语言服务插件:
    " :CocInstall coc-vimlsp
    " :CocInstall coc-sql
    " :CocInstall coc-xml
    " :CocInstall coc-html
    " :CocInstall coc-css
    " :CocInstall coc-eslint    " 需要eslint: sudo npm install -g eslint
    " :CocInstall coc-tsserver
    " [x] :CocInstall coc-ccls      " 需要ccls: sudo dnf install ccls. 存在问题, 改用clangd
    " :CocInstall coc-clangd    " 需要clangd
    " :CocInstall coc-cmake
    " :CocInstall coc-java      " 需要jdtls: 要求版本0.57.
    "                               下载地址: https://download.eclipse.org/jdtls/milestones/0.57.0/
    "                               安装到coc插件目录: ~/.config/coc/extensions/coc-java-data/server
    "                               当自动安装失败, 或jdtls启动失败时, 可尝试手动安装
    " :CocInstall coc-lombok
    " :CocInstall coc-go        " 需要gotags/gopls:
    "                               sudo dnf install gotags golang-x-tools-gopls
    " :CocInstall coc-pyright   " 需要pylint/jedi:
    "                               sudo pip3 install pylint jedi
    " 补全插件:
    " :CocInstall coc-tabnine   " AI补全, 内存占用极大
    " :CocInstall coc-omni
    " 其他插件:
    " :CocInstall coc-highlight
    " 补全提示文档窗口滚动映射键
    if has('nvim-0.4.0') || has('patch-8.2.0750')
        nnoremap <silent><nowait><expr> <C-f> coc#float#has_scroll() ? coc#float#scroll(1) : "\<C-f>"
        nnoremap <silent><nowait><expr> <C-b> coc#float#has_scroll() ? coc#float#scroll(0) : "\<C-b>"
        inoremap <silent><nowait><expr> <C-f> coc#float#has_scroll() ? "\<c-r>=coc#float#scroll(1)\<cr>" : "\<Right>"
        inoremap <silent><nowait><expr> <C-b> coc#float#has_scroll() ? "\<c-r>=coc#float#scroll(0)\<cr>" : "\<Left>"
        vnoremap <silent><nowait><expr> <C-f> coc#float#has_scroll() ? coc#float#scroll(1) : "\<C-f>"
        vnoremap <silent><nowait><expr> <C-b> coc#float#has_scroll() ? coc#float#scroll(0) : "\<C-b>"
    endif
    " 代码跳转
    nmap <leader>sd <Plug>(coc-definition)
    nmap <leader>sr <Plug>(coc-references)
    nmap <leader>st <Plug>(coc-type-definition)
    nmap <leader>si <Plug>(coc-implementation)
    " 代码审查
    nmap <leader>sp <Plug>(coc-diagnostic-prev)
    nmap <leader>sn <Plug>(coc-diagnostic-next)
    " coc-highlight映射键
    autocmd CursorHold * silent call CocActionAsync('highlight')
" }
" EXVIM:
" { main            main repository of exVim
    Plug 'exvim/main'
" }
" { ex-config       exVim默认配置选项、高亮配置和基本语法
    Plug 'exvim/ex-config'
    " ctags选项
    let g:ex_config_ctags_options = '--c++-kinds=+plx --fields=+iaS --extra=+q'
    " ex-tools路径
    let g:ex_tools_path = $VIM.'/vimfiles/tools/'
    " DISABLE: nnoremap <unique> <leader>ve :call exconfig#edit_cur_vimentry ()<CR>

    " { modify_note
        " [autoload/exconfig.vim]
        " @@ -339,2 +339,2 @@ function exconfig#apply()
        " -    if exists('*g:exvim_post_init')
        " -        call g:exvim_post_init()
        " +    if exists('*g:Exvim_post_init')
        " +        call g:Exvim_post_init()
        " @@ -485,0 +486,3 @@ function exconfig#gen_sh_update_ctags(path)
        " +    if g:ex_config_ctags_options != ''
        " +        let ctags_optioins = g:ex_config_ctags_options
        " +    endif
    " }
" }
" { ex-utility      exVim通用脚本函数库
    Plug 'exvim/ex-utility'
    " DISABLE: nnoremap <unique> <silent> <Leader>bd :EXbd<CR>
    " DISABLE: nnoremap <unique> <silent> <C-n> :EXbn<CR>
    " DISABLE: nnoremap <unique> <silent> <C-p> :EXbp<CR>
    " DISABLE: nnoremap <unique> <silent> <C-Tab> :EXbalt<CR>
    " DISABLE: nnoremap <unique> <silent> <Leader><Tab> :EXsw<CR>
    " DISABLE: nmap <unique> <silent> <Leader><Esc> :EXgp<CR>
" }
" { ex-aftercolors  配置after colors
    Plug 'exvim/ex-aftercolors'
" }
" { ex-vimentry     工程入口文件管理
    Plug 'exvim/ex-vimentry'
    " { modify_note
        " [autoload/vimentry.vim]
        " @@ -91 +91 @@ function vimentry#write_default_template()
        " -                \ s:write_default( "enable_gsearch", "true", "{ true, false  }"  ),
        " +                \ s:write_default( "enable_gsearch", "false", "{ true, false  }"  ),
        " @@ -95,3 +95,3 @@ function vimentry#write_default_template()
        " -                \ s:write_default( "enable_symbols", "true", "{ true, false  }"  ),
        " -                \ s:write_default( "enable_inherits", "true", "{ true, false  }"  ),
        " +                \ s:write_default( "enable_symbols", "false", "{ true, false  }"  ),
        " +                \ s:write_default( "enable_inherits", "false", "{ true, false  }"  ),
    " }
" }
" { ex-project      工程管理
    Plug 'exvim/ex-project'
    let g:ex_project_winsize = 32
    let g:ex_project_winsize_zoom = 64
    let g:ex_project_winpos = 'right'
    let g:ex_project_enable_help = 1
    " { modify_note
        " [ex-config/autoload/exproject.vim]
        " @@ -371,1 +371,1 @@ function exproject#init_buffer()
        " -        silent loadview
        " +        " silent loadview
    " }
" }
" { ex-qfix         quick fix for exVim
    Plug 'exvim/ex-qfix'
    let g:exQF_window_direction = 'rightbelow'
" }
" { ex-showmarks    标记功能增强 invoke by m... or <leader>mm, <leader>ma
" TODO: Wait for research
    Plug 'exvim/ex-showmarks'
    " WARN: bootleq/ShowMarks on github is well organized in code, but have lots
    " bugs, consider merge his code and fixes the bugs
    let g:showmarks_enable = 1
    let g:showmarks_include = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'
    let g:showmarks_ignore_type = 'hqm' " Ignore help, quickfix, non-modifiable buffers
    " Hilight lower & upper marks
    let g:showmarks_hlline_lower = 1
    let g:showmarks_hlline_upper = 0
" }
" { ex-visincr      快捷递增输入 invoke when Visual-Block select text and type ':II'
    Plug 'exvim/ex-visincr'
" }
" { ex-matchit      invoke by %
    Plug 'exvim/ex-matchit'
" }
" { ex-searchcompl  '/'和'?'搜索<Tab>补全
    Plug 'exvim/ex-searchcompl'
" }
" BROWSER:
" { undotree        修改历史列表
" FIXME: 窗口创建的宽度存在问题
    Plug 'mbbill/undotree'
    " 窗口布局模式
    let g:undotree_WindowLayout = 1
    " 窗口宽度
    let g:undotree_SplitWidth = 28
    " 对比窗口高度
    let g:undotree_DiffpanelHeight = 9
    " 自动打开对比窗口
    let g:undotree_DiffAutoOpen = 1
    " 打开undotree窗口时移动光标到窗口内
    let g:undotree_SetFocusWhenToggle = 0
    " 0 = 显示绝对时间标  1 = 显示相对时间标
    let g:undotree_RelativeTimestamp = 0
    " 高亮显示当前修改的内容
    let g:undotree_HighlightChangedText = 1
    " 自定义映射
    nnoremap <leader>u :UndotreeToggle<CR>
    " 自定义undotree窗口内部的映射
    " function g:Undotree_CustomMap()
    "     nnoremap <silent> <script> <buffer> <ESC> :call UndotreeHide()<CR>
    " endfunction
" }
" GIT:
" { fugitive        Git管理. Invoke most by :Git *** :Gdiff :Gstatus ...
    Plug 'tpope/vim-fugitive'
" }
" { gitgutter       通过git对比显示修改标记
    Plug 'airblade/vim-gitgutter'
    " 启用插件
    let g:gitgutter_enabled = 1
    " 显示标记栏
    let g:gitgutter_signs = 1
    " 显示修改行高亮
    let g:gitgutter_highlight_lines = 0
    " 自定义行高亮配色
    let g:gitgutter_override_sign_column_highlight = 1
    " 实时运行
    let g:gitgutter_realtime = 0
    " 主动模式
    let g:gitgutter_eager = 0
    " 标记栏标记
    let g:gitgutter_sign_added = '+'
    let g:gitgutter_sign_modified = '!'
    let g:gitgutter_sign_removed = '-'
    let g:gitgutter_sign_modified_removed = '!-'
    " " Sign colors:
    hi GitGutterAdd             guifg=#00df00 guibg=#121212 ctermfg=40  ctermbg=233
    hi GitGutterChange          guifg=#ffaf00 guibg=#121212 ctermfg=214 ctermbg=233
    hi GitGutterDelete          guifg=#ff0000 guibg=#121212 ctermfg=196 ctermbg=233
    hi GitGutterChangeDelete    guifg=#ffaf00 guibg=#121212 ctermfg=214 ctermbg=233
    " " Lines colors:
    " GitGutterAddLine          " default: links to DiffAdd
    " GitGutterChangeLine       " default: links to DiffChange
    " GitGutterDeleteLine       " default: links to DiffDelete
    " GitGutterChangeDeleteLine " default: links to GitGutterChangeLineDefault
" }
" COMPLETER_FORMATTER:
" { auto-pairs      匹配括号自动补全
    Plug 'jiangmiao/auto-pairs'
" }
" { vim-go          Go语法检查&自动格式化
    Plug 'fatih/vim-go', { 'do': ':GoUpdateBinaries' }
    let g:go_bin_path = $HOME.'/go'
    let g:go_code_completion_enabled = 0
    let g:go_highlight_space_tab_error = 1
    let g:go_highlight_trailing_whitespace_error = 0
    let g:go_highlight_operators = 1
    let g:go_highlight_functions = 1
    let g:go_highlight_function_parameters = 1
    let g:go_highlight_function_calls = 1
    let g:go_highlight_types = 1
    let g:go_highlight_fields = 1
    let g:go_highlight_build_constraints = 1
    let g:go_highlight_generate_tags = 1
    let g:go_highlight_format_strings = 1
    let g:go_highlight_variable_declarations = 1
    let g:go_highlight_variable_assignments = 1
    let g:go_fmt_autosave = 1
    let g:go_asmfmt_autosave = 1
    let g:go_mod_fmt_autosave = 1
    let g:go_fmt_options = {
                \ 'gofmt': '-s',
                \ }
" }
" { vim-vue         Vue语法高亮&缩进支持
    Plug 'posva/vim-vue'
" }
" { vim-prettier    自动规范代码风格
    Plug 'prettier/vim-prettier', {
                \ 'do': 'yarn install',
                \ 'for': [  'javascript',
                \           'typescript',
                \           'css',
                \           'less',
                \           'scss',
                \           'json',
                \           'graphql',
                \           'markdown',
                \           'vue',
                \           'yaml',
                \           'html']
                \ }
" }
" { Visincr         快捷递增输入. Visual-Block selected and type :I, :II, :IO, :IIO, :IR, :IIR, IX
    Plug 'vim-scripts/Visincr'
" }
" { vim-easy-align  代码对齐. selected and type :EasyAlign
    Plug 'junegunn/vim-easy-align'
" }
" { nerdcommenter   快捷注释 invoke by <leader>cc, ...
    Plug 'scrooloose/nerdcommenter'
    " 在左注释符之后, 右注释符之前插入空格
    let g:NERDSpaceDelims = 1
    " 在取消注释后同时去掉添加的空格
    let g:NERDRemoveExtraSpaces = 1
    " 其他类型的文件的注释符
    let g:NERDCustomDelimiters = {
        \ 'vimentry': { 'left': '--' },
        \ }
" }
" { DoxygenToolkit  自动生成文件说明或函数注释 invoked by command: ":Dox", ...
    Plug 'https://github.com/vim-scripts/DoxygenToolkit.vim'
    let g:DoxygenToolkit_briefTag_pre           = "\\brief       "
    let g:DoxygenToolkit_templateParamTag_pre   = "\\tparam      "
    let g:DoxygenToolkit_paramTag_pre           = "\\param       "
    let g:DoxygenToolkit_returnTag              = "\\return      "

    let g:DoxygenToolkit_fileTag                = "\\file        "
    let g:DoxygenToolkit_authorTag              = "\\author      "
    let g:DoxygenToolkit_dateTag                = "\\date        "
    let g:DoxygenToolkit_versionTag             = "\\version     "

    let g:DoxygenToolkit_blockHeader            = ""
    let g:DoxygenToolkit_blockFooter            = ""
    let g:DoxygenToolkit_blockTag               = "\\block:      "
    let g:DoxygenToolkit_classTag               = "\\class:      "

    let g:DoxygenToolkit_startCommentTag        = "/**"
    let g:DoxygenToolkit_interCommentTag        = "* "
    let g:DoxygenToolkit_endCommentTag          = "*/"
    let g:DoxygenToolkit_startCommentBlock      = "/**"
    let g:DoxygenToolkit_interCommentBlock      = "* "
    let g:DoxygenToolkit_endCommentBlock        = "*/"

    let g:DoxygenToolkit_authorName             = "huanglf"
    let g:DoxygenToolkit_undocTag               = "DOX_SKIP_BLOCK"
    let s:licenseTag                            = "Copyright(C) "
    let s:licenseTag                            = s:licenseTag."For free. "
    let s:licenseTag                            = s:licenseTag."All right reserved."
    let g:DoxygenToolkit_licenseTag             = s:licenseTag

    " 生成函数说明摘要时, 添加函数名
    let g:DoxygenToolkit_briefTag_funcName      = "no"
    " 注释中添加命名空间名
    let g:DoxygenToolkit_briefTag_namespaceName = "no"
    " 枚举定义说明中添加枚举类型名
    let g:DoxygenToolkit_briefTag_enumName      = "no"
    " 结构体定义说明中添加结构体名
    let g:DoxygenToolkit_briefTag_structName    = "no"
    " 类定义说明中添加类名
    let g:DoxygenToolkit_briefTag_className     = "no"
    " 使用紧凑型注释, 不留空行
    let g:DoxygenToolkit_compactDoc             = "yes"
    " 使用紧凑型注释, 只有brief的注释压缩为一行
    let g:DoxygenToolkit_compactOneLineDoc      = "yes"
    let g:DoxygenToolkit_maxFunctionProtoLines  = 80
" }
" SEARCH:
" { LeaderF         文件搜索. invoke by <leader>ff
    " nvim依赖pynvim: pip3 install pynvim
    Plug 'Yggdroot/LeaderF'
    " 文件搜索触发键
    let g:Lf_ShortcutF = '<leader>ff'
    " 缓存搜索触发键
    let g:Lf_ShortcutB = '<leader>fb'
    " 光标闪烁
    let g:Lf_CursorBlink = 0
    " 状态栏分隔符
    let g:Lf_StlSeparator = { 'left': '', 'right': '' }
    " 修改内建映射
    let g:Lf_CommandMap = {'<C-S>': ['<C-V>']}
    " 忽略匹配
    let g:Lf_WildIgnore = {
            \ 'dir': ['.svn','.git','.hg'],
            \ 'file': ['*.sw?','~$*','*.bak','*.exe','*.o','*.so','*.py[co]']
            \}
    " 如果工程有版本管理, 则使用版本管理工具索引文件, g:Lf_WildIgnore将失效
    let g:Lf_UseVersionControlTool = 1
" }
" { ctrlsf          全局搜索
    Plug 'dyng/ctrlsf.vim'
    let g:ctrlsf_auto_focus = {
                \ "at": "start"
                \ }
    " 结果上下文行数
    let g:ctrlsf_context = '-C 1'
    " 1:正则搜索, 或使用-R选项
    let g:ctrlsf_regex_pattern = 0
    " 异步搜索
    let g:ctrlsf_search_mode = 'async'
    " 紧凑显示
    let g:ctrlsf_default_view_mode = 'compact'
    let g:ctrlsf_position = 'bottom'
    let g:ctrlsf_winsize = '30%'
    nmap     <leader>gg <Plug>CtrlSFCwordExec
    vmap     <leader>gg <Plug>CtrlSFVwordExec
    nmap     <leader>gw <Plug>CtrlSFCCwordExec
    nmap     <leader>gp <Plug>CtrlSFPwordExec
    nnoremap <leader>go :CtrlSFOpen<CR>
    nnoremap <leader>gt :CtrlSFToggle<CR>
    inoremap <leader>gt <Esc>:CtrlSFToggle<CR>
" }
" HIGHLIGHT:
" { nvim-treesitter 语法高亮插件
    Plug 'nvim-treesitter/nvim-treesitter', {'do': ':TSUpdate'}
    " TODO: 配置未生效, 待完善
    " lua require'nvim-treesitter.configs'.setup{highlight={enable=true}}
    " Plug 'nvim-treesitter/nvim-treesitter-refactor'
" }
" { semantic-highlight 随机高亮. Invoke by :SemanticHighlight
    Plug 'jaxbot/semantic-highlight.vim'
" }
" { vim-lsp-cxx-highlight 基于lsp的cxx高亮
    Plug 'jackguo380/vim-lsp-cxx-highlight'
    let g:lsp_cxx_hl_use_text_props = 1
" }
" { TagHighlight    基于ctags的标签高亮插件
" NOTE: 生成标记文件的路径设置在Exvim_post_init中
    Plug 'https://github.com/vim-scripts/TagHighlight'
    if ! exists('g:TagHighlightSettings')
        let g:TagHighlightSettings = {}
    endif
    " 高亮局部变量
    let g:IncludeLocals = 1
" }
" { rainbow         括号高亮匹配
    Plug 'luochen1990/rainbow'
    let g:rainbow_active = 1
    let g:rainbow_conf = {
                \ 'guifgs': [
                \   '#ff0000',
                \   '#ff8700',
                \   '#ffff00',
                \   '#87ff00',
                \   '#00ff00',
                \   '#00ff87',
                \   '#00ffff',
                \   '#00a7ff',
                \   '#5f5fff',
                \   '#a700ff',
                \   '#ff00ff',
                \   '#ff0087',
                \ ],
                \ 'ctermfgs': [
                \   196,
                \   208,
                \   226,
                \   118,
                \   46,
                \   48,
                \   51,
                \   33,
                \   63,
                \   93,
                \   13,
                \   198,
                \ ],
                \ 'operators': '_,_',
                \ 'parentheses': [
                \   'start=/(/ end=/)/ fold',
                \   'start=/\[/ end=/\]/ fold',
                \   'start=/{/ end=/}/ fold',
                \ ],
                \ 'separately': { '*': {}, }
                \ }
" }
" OTHER:
" { easymotion      快速跳转 invoke by <leader><leader> w,b,e,ge,f,F,h,i,j,k,/
    Plug 'Lokaltog/vim-easymotion'
" }
" { indent-guides   缩进指示条 invoke by <leader>ig
    Plug 'nathanaelkane/vim-indent-guides'
    " 自启动
    let g:indent_guides_enable_on_vim_startup = 1
    " 自动配色
    let g:indent_guides_auto_colors = 0
    " 缩进颜色改变比例
    let g:indent_guides_color_change_percent = 4
    " 缩进指示条宽度
    let g:indent_guides_guide_size = 1
    " Tab显示缩进指示高亮
    let g:indent_guides_tab_guides = 1
    " 空格显示缩进指示高亮
    let g:indent_guides_space_guides = 1
" }
" { color-table     终端颜色表 Use for match term color and gui color
    Plug 'https://github.com/guns/xterm-color-table.vim'
" }
" { vimim.vim       内部中文输入法, invoked by <c-_>, switch mode by <c-^>
    Plug 'https://github.com/vim-scripts/VimIM'
    let g:vimim_cloud = 'sogou'
    let g:vimim_map = 'tab_as_gi'
    " let g:vimim_mode = 'dynamic'
    " let g:vimim_mycloud = 0
    let g:vimim_plugin = $VIM . '/vimfiles/tools/pinyin/'
    " let g:vimim_punctuation = 2
    " let g:vimim_shuangpin = 0
    let g:vimim_toggle = 'pinyin,sogou'
    " 当前设置：在输入模式中，按<c-^>的输入法切换顺序为：
    "       搜狗本地字库 => 搜狗联网字库 => Unknown => Unknown => Unknown
" }
" WEB:
" { vim-markdown    Markdowm语法支持
    Plug 'plasticboy/vim-markdown'
    " 禁用折叠
    let g:vim_markdown_folding_disabled=0
    " 使用数学符号
    let g:vim_markdown_math=1
" }
" { markdown-preview.nvim   Markdown实时预览, invoked by :MarkdownPreview
    Plug 'iamcco/markdown-preview.nvim', { 'do': 'cd app & yarn install'  }
    " 1: 打开markdown文件buffer时自动打开预览
    let g:mkdp_auto_start = 0
    " 1: 关闭buffer时自动关闭预览
    let g:mkdp_auto_close = 1
    " 1: 仅保存或退出编辑模式时刷新预览
    let g:mkdp_refresh_slow = 1
    " 预览使用的浏览器
    let g:mkdp_browser = ''
    " 显示预览地址
    let g:mkdp_echo_preview_url = 1
    " 自定义端口, 使用固定端口会导致无法多开
    let g:mkdp_port = ''
    " 局域网内可访问
    let g:mkdp_open_to_the_world = 1
    " 默认主题
    " let g:mkdp_theme = 'light'
    " 样式配置
    let g:mkdp_markdown_css = $VIM.'/vimfiles/tools/css/markdown.css'
    let g:mkdp_highlight_css = $VIM.'/vimfiles/tools/css/highlight.css'
    " 转换选项.
    " uml.imageFormat: 默认为img, 生成png图片, png中文字体模糊, 改用svg图片
    let g:mkdp_preview_options = {
                \ 'uml': { 'imageFormat': 'svg' },
                \ }
" }
" { vim-table-mode  表格格式化插件, invoke by <leader>tm
    Plug 'dhruvasagar/vim-table-mode'
" }
" AFTER:
" { AFTER           最后加载的插件配置
function g:Exvim_post_init()
" EXVIM:
" { TagHighlight    标签高亮插件
    " DoNotGenerateTags: 不自动生成tags, 存在问题
    " ProjectConfigFileDirectory: 配置文件路径，用于包含其他库的taghl文件
    " ProjectConfigFileName:  Default: 'taghl_config.txt'
    " TagFileDirectory: 当前工程的tags文件路径
    " TypesFileDirectory: 生成的taghl文件路径
    let g:TagHighlightSettings = {
                \ 'DoNotGenerateTags'   : 1,
                \ 'ProjectConfigFileDirectory'  : g:exvim_folder,
                \ 'ProjectConfigFileName'       : 'taghl_config.txt',
                \ 'TagFileDirectory'    : g:exvim_folder,
                \ 'TypesFileDirectory'  : g:exvim_folder,
                \ }
" }
" CTAGS:
" { ctags           外部tags加载
    " set tags+=/usr/include/qt5/.exvim.qt5_inc/tags
" }
endfunction
" }

" All of your Plugs must be added before the following line
call plug#end()

